/*
*	(*^。^*) TFrameWork License (*^。^*)
*/

/*
 *  Title :  
 *          
 *  Description :  
 *          
 *          
 *  Date : 
 *
 *  Author : DengPing
 *
 *  Modify : 
 */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TFrameWork.Module.ActionEditor
{
    public class CameraFollow : MonoBehaviour
    {
        public Transform target; // 角色对象
        public float smoothSpeed = 5; // 相机跟随的平滑度
        public Vector3 offset = new Vector3(0, 2, -5); // 相机偏移量

        private void LateUpdate()
        {
            if (target == null)
                return;

            // 计算相机的目标位置
            Vector3 desiredPosition = target.position + offset;

            // 使用 SmoothDamp 函数平滑移动相机
            Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed * Time.deltaTime);
            transform.position = smoothedPosition;

            // 让相机始终朝向角色
            transform.LookAt(target);
        }
    }

}
